$(document).ready(function(){


  
    var imgWidth = -785;
    
   
    
    
    $('.panelimg').each(function(index){
    
        console.log($('.panelimg').length + ":" + index);
        
        $('<div></div>').appendTo('.panel_controll').addClass('controll').attr("index", (index + 1)).click(function(event){
        
            var $index = $(this).attr('index');
            
            $('.slide_panel').animate({
            
                'left': imgWidth * ($index) + "px"
            
            }, 800);
            
            $(".controll").removeClass('currnt');
            $(this).addClass('currnt');
            
        });
        
        $(this).click(function(){
        
            console.log('click the img..');
            $(".controll").each(function(index2){
            
                console.log("index2:" + index2 + "——index:" + index);
                
                if (index2 == index) {
                    $(".controll").removeClass('currnt');
                    $(this).addClass('currnt');
                    
                }
                
            });
            
            $('.slide_panel').animate({
            
                'left': imgWidth * (index + 1) + "px"
            
            }, 800);
            
            
        });
        
    });
    
	 $('#login').click(function(){
    
        $('.login-panel').slideDown('fast');
        
    });
    
    $('#close-login').click(function(){
    
        $('.login-panel').slideUp('fast');
        
    });
	
    /**登录验证*/
    $('#login-form').submit(function(){
    
		
        $.post('login', $(this).find('input').serialize(), function(data){
        
           var userInfo = $.xml2json(data);
		   var status = userInfo.status;
		   if(status=="false"){
		   		
				alert("登录失败。。");
				return;
			}
			var email = userInfo.useremail;
			var username = userInfo.username;
            //alert("email:"+email+",name:"+username);
			$('#loginpanel').hide();
			$('#welcomepanel').show();
			$('#loginer').html(username);
			$('.login-panel').slideUp('fast');
        });
       
        return false;
        
    });
	
	/**退出登录*/
	$('#butn_logout').click(function(event){
		
		$.get('logout',null,function(data){
			
			if(data=="success"){
				
				$('#loginpanel').show();
				$('#welcomepanel').hide();
				
			}
			
			event.stopPropagation();
			event.preventDefault();
		});
		
	});
    
});

